//
//  IntersitialDemoVC.m
//  JAGatherAdDemo
//
//  Created by Yc on 2022/4/24.
//

#import "IntersitialDemoVC.h"
#import <JAGatherAdSDK/JAGatherAdSDK.h>
#import "PlacementVC.h"

@interface IntersitialDemoVC ()<JAGAdInterstitialDelegate>

@property (nonatomic, strong) JAGAdInterstitial *interstitial;

@end

@implementation IntersitialDemoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.placementList = [[NSMutableArray alloc] initWithArray:[self readPlacementDataOfType:DataType_interstitial]];
    [self setupPlacement:interstitialID];
    [self creatIntersitial];
}

- (void)creatIntersitial {
    [self deallocAd];
    self.interstitial = [[JAGAdInterstitial alloc] initWithPlacementID:[self getPlacement]];
    self.interstitial.viewController = self;
    self.interstitial.delegate = self;
}

- (void)deallocAd {
    self.interstitial = nil;
    self.interstitial.delegate = nil;
}

- (void)loadAdAction {
    [super loadAdAction];
    NSLog(@"%s", __FUNCTION__);
    TOAST(@"开始加载广告数据");
    [self.interstitial loadAd];
    [self writePlacementDataOfType:DataType_interstitial];
}

- (void)showAdAction {
    [super showAdAction];
    NSLog(@"%s", __FUNCTION__);
    if (self.interstitial) {
        [self.interstitial showAd];
    }
}

- (void)loadAndShowAdAction {
    [super loadAndShowAdAction];
    NSLog(@"%s", __FUNCTION__);
    TOAST(@"开始加载广告数据");
    [self.interstitial loadAndShowAd];
    [self writePlacementDataOfType:DataType_interstitial];
}

- (void)reselectPlacementAction {
    [self creatIntersitial];
}

- (void)dealloc {
    NSLog(@"%s", __FUNCTION__);
}

#pragma mark - JAGAdInterstitialDelegate

/// 插屏广告数据请求成功
- (void)JAGatherInterstitialAdSuccessLoad:(JAGAdInterstitial *)interstitial {
    NSLog(@"%s", __FUNCTION__);
    TOAST(@"数据加载完成");
}

/// 插屏广告数据请求失败
- (void)JAGatherInterstitialAdFailLoad:(JAGAdInterstitial *)interstitial error:(NSError *)error {
    NSLog(@"%s %@", __FUNCTION__,error);
    NSString *msg = [NSString stringWithFormat:@"%@",error];
    TOAST(msg);
}

/// 插屏广告曝光回调
- (void)JAGatherInterstitialAdExposured:(JAGAdInterstitial *)interstitial {
    NSLog(@"%s", __FUNCTION__);
}

/// 插屏广告点击回调
- (void)JAGatherInterstitialAdClicked:(JAGAdInterstitial *)interstitial {
    NSLog(@"%s", __FUNCTION__);
}

/// 插屏广告页关闭
- (void)JAGatherInterstitialAdClosed:(JAGAdInterstitial *)interstitial {
    NSLog(@"%s", __FUNCTION__);
}

/// 插屏广告落地页关闭
- (void)JAGatherInterstitialAdCloseLandingPage:(JAGAdInterstitial *)interstitial {
    NSLog(@"%s", __FUNCTION__);
}

@end
